package com.yqd.lesson.actor.three

import java.lang

import akka.actor.SupervisorStrategy.{Escalate, Restart, Stop}
import akka.actor.{Actor, ActorInitializationException, ActorKilledException, ActorLogging, DeathPactException, OneForOneStrategy, Props, SupervisorStrategy}


object Receiver{
  def props:Props = Props[Receiver]
}

class Receiver extends Actor with ActorLogging{

  override def receive: Receive = {
    case msg:String =>
      log.info(msg)
      throw new NullPointerException("I'm null.")
    case msg:Int =>
      throw new ArithmeticException("I'm zero.")
  }

  override def preStart(): Unit = {
    super.preStart()
    log.info("-------preStart------")
  }

  override def unhandled(message: Any): Unit = {
    super.unhandled(message)
    log.info("-------unhandled------")
  }

  override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
    super.preRestart(reason, message)
    log.info("-------preRestart------")
  }

  override def postRestart(reason: Throwable): Unit = {
    super.postRestart(reason)
    log.info("-------postRestart------")
  }

  override def postStop(): Unit = {
    super.postStop()
    log.info("-------postStop------")
  }
}
